# Maintainer: Jenneron <jenneron@protonmail.com>
pkgname=cros-keyboard-map
pkgdesc="Keyboard mapping for Chrome OS devices"
pkgver=0_git20240313
pkgrel=0
url="https://github.com/WeirdTreeThing/cros-keyboard-map"
license="BSD-3-Clause"
arch="aarch64 armv7 x86_64" # there are no cros devices of other arches
depends="keyd python3"

case "$CARCH" in
aarch64|armv7)
	depends="$depends py3-libfdt"
	;;
esac

options="!check !archcheck !tracedeps"
subpackages="$pkgname-openrc"
_repo="WeirdTreeThing/cros-keyboard-map"
_commit="1cf87a401dfc99d518ef84965ce3cb83993a3f25"
source="
	cros-keyboard-map-$_commit::https://raw.githubusercontent.com/$_repo/$_commit/cros-keyboard-map.py
	$pkgname.initd
	$pkgname.confd
"

package() {
	# Script
	install -Dm755 "$srcdir/cros-keyboard-map-$_commit" \
		"$pkgdir"/usr/bin/pmos-generate-cros-keymap

	# OpenRC service
	install -Dm755 "$srcdir/$pkgname.initd" \
		"$pkgdir/etc/init.d/$pkgname"
	install -Dm644 "$srcdir"/$pkgname.confd \
		"$pkgdir/etc/conf.d/$pkgname"

	# We generate config in runtime with OpenRC service, thus make a symlink for
	# keyd config to a file in /tmp that will be generated with the service
	_dir="$pkgdir/etc/keyd"
	mkdir -p "$_dir"
	ln -s /tmp/cros-keymap/keyd.conf "$_dir"/default.conf
}

sha512sums="
596743d994d118e52b3f1cdf30748f03f6520dd458af34107ec68c5ab31e2de4984275835c920b33568b6bf210a77e92e3b01b6359bb06d547b9b76d177d284e  cros-keyboard-map-1cf87a401dfc99d518ef84965ce3cb83993a3f25
bcb3bfa30b3e670dca3c90168eb71d9eef4cad6b098dc878e8b572102f43f958ac5f9af603df393cabf4278ee4232714d626ada9d5ac22174ed7ceac17176c3d  cros-keyboard-map.initd
81d435d611927bc69d49cf4ed7f1fe3df33f001aec27397a8683b827ba9f5d5b3bfa0a3ab2b58d07b275e49e0300c0d91b5a1930b023791e312e55569b329dcb  cros-keyboard-map.confd
"
